package com.java.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.java.domain.UserDo;
import com.java.service.UserService;
import com.java.utils.EmailUtils;
import com.java.utils.JsonUtils;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@Controller
@Scope("prototype")
public class InformManageAction extends ActionSupport implements
		ModelDriven<UserDo> {

	private static final long serialVersionUID = 12L;

	@Resource
	private UserService userService;

	public void sendEmail() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String email = request.getParameter("email");
		String name = request.getParameter("name");
		String title = name + "用户你好,病例完善通知";
		String content = "尊敬的用户你好,你的病例已经完善,请注意与医生沟通,账号:" + name + "密码为你的手机号码";
		content += "点击链接地址查看病例 <a href='http://localhost:8080/docSystem/login_list.do'>http://localhost:8080/docSystem/login_list.do</a>";
		Properties prop = new Properties();
		try {
			prop.load(InformManageAction.class.getClassLoader()
					.getResourceAsStream("email.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		EmailUtils.sendMessage(email, title, content,
				(String)prop.getProperty("emailname"), (String)prop.getProperty("emailpsw"));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("success", "success");
		JsonUtils.JsonTostring(map);
	}

	public void showManList() {
		List<UserDo> list = userService.queryAllPatient(0);
		JsonUtils.JsonTostring(list);
	}

	public String showInformManage() {
		return "showInformManage";
	}

	public UserDo getModel() {
		return null;
	}

}
